package com.zlx.mall.basic.web.holder;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.zlx.mall.basic.web.filter.ContextHolderListener;
import org.springframework.util.ObjectUtils;

/**
 * @author qingke
 * @see org.springframework.web.context.request.RequestContextHolder
 **/
public class IdContextHolder {

    public static final TransmittableThreadLocal<String> ID = new TransmittableThreadLocal<>();

    static {
        ContextHolderListener.register(ID);
    }

    public static String getId() {
        return ID.get();
    }

    public static void setId(Object value) {
        ID.set(ObjectUtils.getDisplayString(value));
    }

    public static void remove() {
        ID.remove();
    }
}
